package com.revenant.driver.ui.activity;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.revenant.driver.R;
import com.revenant.driver.adapter.NewMainAdapter;
import com.revenant.driver.base.BaseActivity;
import com.revenant.driver.ui.fragment.AssessmentFragment;
import com.revenant.driver.ui.fragment.DaiJieSuanFragment;
import com.revenant.driver.ui.fragment.DaiPingJiaFragment;
import com.revenant.driver.ui.fragment.DaiZhuangHuoFragment;
import com.revenant.driver.ui.fragment.DriverFourFragment;
import com.revenant.driver.ui.fragment.DriverOrderFragment;
import com.revenant.driver.ui.fragment.DriverOrderTwoFragment;
import com.revenant.driver.ui.fragment.DriverThreeeFragment;
import com.revenant.driver.ui.fragment.InTransitFragment;
import com.revenant.driver.ui.fragment.OrderAllFragment;
import com.revenant.driver.ui.fragment.UnconfirmedFragment;
import com.revenant.driver.ui.fragment.YiXieHuoFragment;
import com.revenant.driver.utils.LocatinNoDataService;
import com.revenant.driver.utils.LocationService;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class DriverOrderActivity extends BaseActivity {
    @BindView(R.id.tablayoutorder)
    TabLayout tablayoutorder;
    @BindView(R.id.viewpagerorder)
    ViewPager viewpagerorder;

    private List<Fragment> fragmentList;
    private List<String> titleList;
    private NewMainAdapter newMainAdapter;
    private int defaultselect = 0;

    @Override
    public int getContentViewResId() {
        return R.layout.activity_driver_order;
    }

    @Override
    public void initView() {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            defaultselect = extras.getInt("orderselect");
        }
        fragmentList = new ArrayList<>();
        titleList = new ArrayList<>();
    }

    @Override
    public void initData() {

        startlocation();
        setcenterTitle("我的订单");

        fragmentList.add(DriverOrderFragment.newInstance("Quanbu"));
        fragmentList.add(DaiZhuangHuoFragment.newInstance("DaiZhuangHuo"));
        fragmentList.add(DriverThreeeFragment.newInstance("JinXingZhong"));
        fragmentList.add(DaiJieSuanFragment.newInstance("DaiJieSuan"));
//        fragmentList.add(DriverOrderTwoFragment.newInstance("DaiQueRen"));
//        fragmentList.add(DaiPingJiaFragment.newInstance("DaiPingJia"));
        fragmentList.add(DriverFourFragment.newInstance("YiWanCheng"));
        fragmentList.add(YiXieHuoFragment.newInstance("YiXieHuo"));

        titleList.add("全部");
        titleList.add("待装货");
        titleList.add("进行中");
        titleList.add("待结算");
//        titleList.add("待确认");
//        titleList.add("待评价");
        titleList.add("已完成");
        titleList.add("卸货");


        newMainAdapter = new NewMainAdapter(getSupportFragmentManager(), this, fragmentList, titleList);
//
        viewpagerorder.setAdapter(newMainAdapter);
        tablayoutorder.setupWithViewPager(viewpagerorder);
        tablayoutorder.getTabAt(defaultselect).select();
    }


    @Override
    public void leftbarclick() {
        super.leftbarclick();
        finish();
    }

    private void startlocation() {
        if (LocationService.getLastLocation() == null) {
            Intent intent = new Intent(DriverOrderActivity.this, LocationService.class);
            startService(intent);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (LocationService.getLastLocation() == null) {
            if (LocatinNoDataService.getLastLocation() == null) {
                Intent intent = new Intent(DriverOrderActivity.this, LocatinNoDataService.class);
                startService(intent);
            }
        }
    }
}
